<?php
	class Moderator extends Member
	{
		public static function EditStemWordList($ID, $action, $word, $changeWord = "")
		{
			$change = false;
			switch ($action)
			{
				// add $word to stemword_table
				case "add":
					if (!empty($word))
					{
						$query = mysql_query("INSERT INTO stemword_table (Stemword, UID) VALUE('$word', $ID)");
						
						if ($query)
							echo "Successfully added word";
						else
							echo "Failed to add word";
						$change = true;
					}
					
					break;
				
				// delete $word from stemword_table;
				case "delete":
					// look for the moderator's keyword (make sure that we don't delete other moderator's stemwords)
					if (!empty($word))
					{
						$query = mysql_query("DELETE FROM stemword_table where Stemword=$word AND UID=$ID");
						$change = true;
					}
					break;
				
				// swap $word with $changeWord
				case "edit":
					// look for the moderator's keyword (make sure that we don't edit other moderator's stemwords)
					if (!empty($word) && !empty($changeWord))
					{
						$query = mysql_query("UPDATE stemword_table SET='$changeWord' WHERE Stemword='$word' AND UID=$ID");
						$change = true;
					}
					break;
				
				default: 
					break;
			}
		}	
		
		public static function EditStopWordList($ID, $action, $word, $changeWord = "")
		{
			$change = false;
			switch ($action)
			{
				// add $word to stemword_table
				case 'add':
					if (!empty($word))
						$query = mysql_query("INSERT INTO stopword_table (Stopword, UID) VALUE('$word', $ID)");

					$change = true;
					break;
				
				// delete $word from stemword_table;
				case 'delete':
					// look for the moderator's stemword (make sure that we don't delete other moderator's stemwords)
					if (!empty($word))
						$query = mysql_query("DELETE FROM stopword_table WHERE Stemword=$word AND UID=$ID");
						
					$change = true;
					break;

				case 'edit':
					// look for the moderator's keyword (make sure that we don't edit other moderator's stemwords)
					if (!empty($word) && !empty($changeWord))
						$query = mysql_query("UPDATE stopword_table SET='$changeWord' WHERE Stemword='$word' AND UID=$ID");
					
					$change = true;
					break;
				
				default: 
					break;
			}
			return $change;
		}
		
		
		public static function RemoveUser($userID)
		{	
			$query = mysql_query("DELETE FROM user_table WHERE UID=$userID");
			if ($query)
				return true;
			
			return false;
		}
		
		public static function ApproveUser($userID)
		{
			$query = mysql_query("UPDATE user_table SET status='member' WHERE UID=$userID");
			if ($query)
				return true;
			
			return false;
		}
		
		public static function ComplaintDecision($complaintID, $decision)
		{
			$removeEntry = false;
			switch ($decision)
			{
				// if we deny complaint, remove complaint from table. No points deducted.
				case "deny":
					$removeEntry = true;
					break;
				
				// if we approve complaint, deduct points from $UID. Then remove complaint from table.
				case "approve":					
					$query = mysql_query("SELECT ID FROM complaint_table WHERE ID=$complaintID");
					
					if ($query)
					{
						$entry = mysql_fetch_array($query);
						$entry = $entry['UID'];
						
						$query2 = mysql_query("SELECT UID, Credits FROM user_table WHERE UID=$entry");
						$userEntry = mysql_fetch_array($query2);
						
						$credits = $userEntry['Credits'] - 0.2;
						$entryID = $userEntry['UID'];
						$query3 = mysql_query("UPDATE user_table SET Credits=$credits WHERE UID=$entryID");
						
						// if we can't perform $query3, then don't delete entry
						if (!$query3)
							break;
					}
					$removeEntry = true;
					break;
				
				// don't do anything for other invalid decision
				default:
					break;
			}	
			
			
			if ($removeEntry)
			{	
				$query = mysql_query("DELETE FROM complaint_table WHERE ID=$complaintID");
				
				if ($query)
					return true;
			}

			return false;		
		}
	}
?>